package com.itsq.service.resources.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.constant.APIException;
import com.itsq.mapper.CarMapper;
import com.itsq.pojo.dto.PageChangeDto;
import com.itsq.pojo.entity.Car;
import com.itsq.pojo.entity.Change;
import com.itsq.mapper.ChangeMapper;
import com.itsq.service.resources.ChangeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 史先帅
 * @since 2021-01-29
 */
@Service
public class ChangeServiceImpl extends ServiceImpl<ChangeMapper, Change> implements ChangeService {

    @Autowired(required = false)
    private ChangeMapper changeMapper;
    @Autowired(required = false)
    private CarMapper carMapper;

    @Override
    public Page<Change> selChangePageFront(PageChangeDto pageChangeDto) {
        Page<Change> page=new Page<>(pageChangeDto.getPageIndex(),pageChangeDto.getPageSize());
        QueryWrapper queryWrapper=new QueryWrapper();
        return changeMapper.selectPage(page,queryWrapper);
    }

    @Override
    public Page<Change> selChangePageAfter(PageChangeDto pageChangeDto) {
        List<Change> list=null;
        Page<Change> page=new Page<>(pageChangeDto.getPageIndex(),pageChangeDto.getPageSize());
        QueryWrapper queryWrapper=new QueryWrapper();
        if(pageChangeDto.getCarNumber()!=null){
            QueryWrapper queryWrapper1=new QueryWrapper();
            queryWrapper1.eq("car_number",pageChangeDto.getCarNumber());
            Car car = carMapper.selectOne(queryWrapper1);
            queryWrapper.eq("car_id",car.getId());
            list = changeMapper.selectList(queryWrapper);
        }
        page.setRecords(list);
        return changeMapper.selectPage(page,queryWrapper);
    }

}
